﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace titan
{
    /// <summary>
    /// Classe abstraite pour dessiner des sprites à l'écran. On généralise au max dans cette classe
    /// pour que les dérivés soient simples.
    /// </summary>
    abstract class Drawable
    {
        /// <summary>
        /// Xtor
        /// </summary>
        public Drawable()
        {
            this.location = new Vector2(-1,-1);
        }

        private Vector2 location;
        public Vector2 Location
        {
            get { return location; }
            set { location = value; }
        }
        private Vector2 location_to_go;
        public Vector2 Location_to_go
        {
            get { return location_to_go; }
            set { location_to_go = value; }
        }

        protected string[] textures_names;
        public string Texture
        {
            get { return textures_names[current_texture]; }
        }

        protected int current_texture=0;

        private enum Movement
        {
            NONE,
            UP,
            DOWN,
            LEFT,
            RIGHT,
            UP_LEFT,
            UP_RIGHT,
            DOWN_LEFT,
            DOWN_RIGHT,
        }

        Movement movement;

        private Constants.CharacterState state;

        public void Update()
        {
            movement = Movement.NONE;
            if (location != location_to_go)
            {
                if (location_to_go.X > location.X)
                {
                    movement = Movement.RIGHT;
                    this.state = Constants.CharacterState.WALKING;
                    location.X++;
                }
                else if (location_to_go.X < location.X)
                {
                    movement = Movement.LEFT;
                    location.X--;
                    this.state = Constants.CharacterState.WALKING;
                }
                if (location_to_go.Y > location.Y)
                {
                    this.state = Constants.CharacterState.WALKING;
                    location.Y++;
                }
                else if (location_to_go.Y < location.Y)
                {
                    location.Y--;
                }
                else
                {
                    this.state = Constants.CharacterState.STOPPED;
                }
            }
        }

        public void UpdateSprite()
        {
            if (this.state == Constants.CharacterState.WALKING)
                current_texture = (current_texture +1 ) % 12 + 1;
        }

    }
}
